#ifndef RING_QUEUE_H
#define RING_QUEUE_H

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>



// 环形队列数组实现
typedef struct RingQueue {
    void* array;
    int front;
    int tail;
    int length;
    int capacity;
} RingQueue;

#define InitRingQueue(RingQueue* queue, int capacity, int totalSize) {
    assert(capacity > 1);
    queue->array = (void*)malloc(totalSize);
    if (!queue->array) {
        return -1;
    }
    queue->front = queue->tail = 0;
    queue->length = 0;
    queue->capacity = capacity;
    return 0;
}

int RingQueueFull(RingQueue queue) {
    return (queue.tail + 1) % queue.capacity == queue.front ? 1 : 0;
}

int RingQueueEmpty(RingQueue queue) {
    return queue.front == queue.tail ? 1 : 0;
}

// 入队
int EnQueue(RingQueue* queue, void data) {
    if (RingQueueFull(*queue)) {
        return -1;
    }

    queue->array[queue->tail] = data;
    queue->tail = (queue->tail + 1) % queue->capacity;
    return 0;
}

int DeQueue(RingQueue* queue, void* data) {
    return 0;
}

#endif // RING_QUEUE_H
